package com.iuie.ns.devtools.element;

import java.util.List;
import java.util.Map;

import com.iuie.ns.devtools.to.DevBodyTO;
import com.iuie.ns.frame.utils.StringUtils;

public class JavaBeanAttributeDevElement extends DevElement {

	private DevBodyTO body;

	private Map<String, String> fieldTypeRelationMap;
	
	public JavaBeanAttributeDevElement(DevBodyTO body, Map<String, String> fieldTypeRelationMap) {
		this.body = body;
		this.fieldTypeRelationMap = fieldTypeRelationMap;
	}

	@Override
	protected String getPrefix() {
		StringBuilder prefix = new StringBuilder(12);
		String javaType = fieldTypeRelationMap.get(body.getFieldType());
		if (javaType != null && javaType.equals("Date")) {
			prefix.append("\t@JsonFormat(pattern=\"yyyy-MM-dd HH:mm:ss\")\n");
		}
		return prefix.toString();
	}

	@Override
	protected String getSuffix() {
		String javaType = fieldTypeRelationMap.get(body.getFieldType());
		String attributeName = body.getAttributeName();
		
		StringBuilder sb = new StringBuilder(12);
		sb.append("\tprivate ")
			.append(javaType)
			.append(" ")
			.append(attributeName)
			.append(";");
		if (StringUtils.isNotBlank(body.getComment())) {
			sb.append(" // ")
				.append(body.getComment());
		}
		sb.append("\n\n");
		return sb.toString();
	}

	@Override
	protected List<DevElement> getChildren() {
		return null;
	}

}
